package com.dqhl.community.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.dqhl.community.R;
import com.dqhl.community.model.ShopCartBean;
import com.dqhl.community.util.Config;
import com.dqhl.community.util.ViewHolder;

import org.xutils.x;

import java.util.List;

/**
 * Created by cheng on 2016/9/20.
 */
public class ShoppingCarPayAdapter extends BaseAdapter {

    private List<ShopCartBean> shopCartBeanList;
    private Context context;
    private LayoutInflater inflater;

    public ShoppingCarPayAdapter(Context context, List<ShopCartBean> shopCartBeanList) {
        this.context = context;
        this.shopCartBeanList = shopCartBeanList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return shopCartBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = inflater.inflate(R.layout.lv_item_shopping_car_pay, viewGroup, false);
        }
        ImageView iv_picture = ViewHolder.get(view, R.id.iv_picture);
        TextView tv_name = ViewHolder.get(view, R.id.tv_name);
        TextView tv_price = ViewHolder.get(view, R.id.tv_price);
        TextView tv_account_number = ViewHolder.get(view, R.id.tv_account_number);

        ShopCartBean shopCartBean = shopCartBeanList.get(i);

        x.image().bind(iv_picture, Config.Api.base_img_url + shopCartBean.getPic_a());
        tv_name.setText(shopCartBean.getName());
        String total = (Double.parseDouble(shopCartBean.getPrice()) * shopCartBean.getNumber()) + "";
        tv_price.setText("￥" + total);
        tv_account_number.setText("x " + shopCartBean.getNumber());

        return view;
    }
}
